package menuListener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenuItem;

import graph.PaintPanel;
import tool.ReadConfig;
import tool.ReadResources;

public class BackGroundListener implements ActionListener {
	private ReadResources readResources;	//资源读取器
	private int type;	//类型
	private PaintPanel paint;
	private ReadConfig readConfig;
	public BackGroundListener(ReadResources readResources,PaintPanel paint,int type,ReadConfig readConfig) {
		this.readResources=readResources;
		this.type=type;
		this.paint=paint;
		this.readConfig=readConfig;
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		JMenuItem mentItem=(JMenuItem) e.getSource();
		switch(type){
		case 0:	//扑克背景
			readResources.readPokerBack(mentItem.getText());	//资源读取器加载背景
			readConfig.setDefaultPokerBack(mentItem.getText());
			break;
		case 1:	//牌桌背景
			readResources.readTableBack(mentItem.getText());
			readConfig.setDefaultTableBack(mentItem.getText());
			break;
		}
		paint.repaint();	//重画
	}

}
